<?xml version = '1.0' encoding = 'UTF-8'?>
<HBRRepo><variables><variable name="OQP_SrcScenario" type="member" usage="const" id="1" product="Planning"><property name="application">SalesPln</property><property name="dimensionInputMode">type</property><property name="dimensionType">Scenario</property><property name="prompt_text">LABEL_QTP_SLS_PLAN_PRMPT_SRC_SCENARIO</property><property name="scope">ruleset</property><property name="seeded">true</property><value/></variable><variable name="OQP_TargetScenario" type="member" usage="const" id="2" product="Planning"><property name="application">SalesPln</property><property name="dimensionInputMode">type</property><property name="dimensionType">Scenario</property><property name="prompt_text">LABEL_QTP_SLS_PLAN_PRMPT_TGT_SCENARIO</property><property name="scope">ruleset</property><property name="seeded">true</property><value/><limits type="expression"><property name="value">@CHILDREN("OEP_What-Ifs"),OEP_Plan</property></limits></variable></variables><rulesets/><rules><rule id="1" name="OQP_Copy Bottomup What If" product="Planning"><property name="application">SalesPln</property><property name="plantype">OEP_QTP</property><property name="seeded">true</property><variable_references><variable_reference name="OQP_SrcScenario" id="1"><property name="application">SalesPln</property><property name="hidden">false</property><property name="rule_name">OQP_Copy Bottomup What If</property><property name="seq">1</property><property name="type">3</property><property name="useAsOverrideValue">false</property><property name="validation_value">OEP_Plan</property></variable_reference><variable_reference name="OQP_TargetScenario" id="2"><property name="application">SalesPln</property><property name="hidden">false</property><property name="rule_name">OQP_Copy Bottomup What If</property><property name="seq">2</property><property name="type">3</property><property name="useAsOverrideValue">false</property><property name="validation_value">OEP_Plan</property></variable_reference></variable_references><script type="groovy">			/*RTPS: {OQP_SrcScenario} , {OQP_TargetScenario} */
            /*Purpose: This business rule Copies data from Source to Target Scenario*/
            String SrcScenario=rtps.OQP_SrcScenario.member.name;
			String TargetScenario=rtps.OQP_TargetScenario.member.name;
			List&lt;String> NewColumnDims =[];
			List&lt;String> RowDimensions = [];
            List&lt;String> CustomDimensions=[];
            List&lt;String> CustomAnyMbrs=[];
			List&lt;String> fixMemberNames = operation.grid.pov*.essbaseMbrName
			List&lt;String> povMembers =[];
            String strCrossDim = "";
            int iCnt;
            
			try{
            Application app=operation.getApplication();
			StringBuilder cscript = new StringBuilder();
			cscript.append('''SET AGGMISSG ON;\n''');
			cscript.append('''SET UPDATECALC OFF;\n''');
			def grid=operation.grid;
			List&lt;DataGrid.HeaderCell> pov=grid.getPov()
            /*Fetch  Row dimensions and their members */
			List&lt;DataGrid.Row> rows = grid.getRows()
			for (DataGrid.Row row : rows) 
			{
				List&lt;DataGrid.HeaderCell> subRows = row.getHeaders();
				for(DataGrid.HeaderCell cell : subRows) 
				  {
					  String memName = cell.getEssbaseMbrName();
                     
				   if (!RowDimensions.contains(memName))
				   {
				   RowDimensions.add('''"'''+memName +'''"''')
				  
				   }     	 
				 }        
			}
			/*Fetch Column dimensions and their members */
			for (DataGrid.HeaderCell cell : pov)
			{
			   String mbrName = cell.getEssbaseMbrName();
			   String dimType = cell.getDimensionType();
               String dimName = cell.getDimName()
			   
				if(!dimType.equals("Scenario") &amp;&amp; !dimType.equals("Simple Currency"))
				{
						strCrossDim= strCrossDim + "\""+ mbrName+"\"->"	
                        povMembers.add('''@RELATIVE("'''+mbrName +'''",0)''');
                        CustomAnyMbrs.add('''"No '''+dimName+'''"''')
                        CustomDimensions.add('''"'''+dimName+'''"''');
				}    
			}
			/*Main Fix*/
			cscript.append('''FIX(@Relative("YearTotal",0),"OQP_Quota","OEP_Working Bottom Up",&amp;OEP_CurYr,''')
            if (app.getCurrencyMode()!=CurrencyMode.SINGLE_CURRENCY)
            {
				String sCurrency =  operation.grid.pov.find { it.dimName == 'Currency' }.essbaseMbrName 
                cscript.append ('''"'''+ sCurrency +'''",''')
            }
			cscript.append(RowDimensions.join(''',''')+''')\n''')
            if (povMembers.size()>0)
            {
				cscript.append('''	FIX('''+povMembers.join(''','''))
				cscript.append(''')\n''')
            }
            /*Copy what if scnearios*/
			cscript.append('''		Datacopy "'''+SrcScenario+'''" to "'''+ TargetScenario +'''";\n''')
            if (povMembers.size()>0)
            {
			cscript.append('''	ENDFIX\n''')
			}
            /*Aggregate What if scenarios*/
            if (CustomDimensions.size()>0)
            {
            		if (CustomDimensions.size()>1)
                     {
                        cscript.append('''	FIX("'''+TargetScenario+'''")\n''')
                        for (iCnt=0;iCnt&lt;CustomDimensions.size()-1;iCnt++)
                        {
                        cscript.append('''			FIX(@RELATIVE('''+CustomDimensions[iCnt]+''',0))\n''')              
                        }                
                        for (iCnt=CustomDimensions.size()-1;iCnt>0;iCnt--)
                        {
                        cscript.append('''				AGG('''+CustomDimensions[iCnt]+''');\n''')                        
                        cscript.append('''			ENDFIX\n''')
                        }
                        cscript.append('''			AGG('''+CustomDimensions[0]+''');\n''')
                        cscript.append('''		ENDFIX\n''')
                    }
                    if (CustomDimensions.size()==1)
                    {
                       cscript.append('''		FIX("'''+TargetScenario+'''")\n''')
                        cscript.append('''	 		AGG('''+CustomDimensions[0]+''');\n''')
                        cscript.append('''		ENDFIX\n''')            
                    }
                    cscript.append('''	FIX('''+CustomAnyMbrs.join(''',''')+''')\n''')
                    cscript.append('''		"'''+TargetScenario+'''"(\n''')
                    cscript.append('''"'''+TargetScenario+'''"="'''+TargetScenario+'''"->'''+strCrossDim+'''"OQP_Quota";\n''')
                    cscript.append('''		)\n''')
            		cscript.append('''	ENDFIX\n''')
            }
            cscript.append('''ENDFIX\n''')

			println (cscript.toString())
			return cscript.toString();
			}catch(all) {
				throw new HspRuntimeException('Error occured while executing business rule');
			}
		 
		</script></rule></rules><components/><deployobjects><deployobject product="2" application="salespln" plantype="oep_qtp" obj_id="1" obj_type="1" name="OQP_COPY BOTTOMUP WHAT IF"/></deployobjects></HBRRepo>